import {cacheTools} from 'nc-lightapp-front'


export default class HeaderAction{
    constructor(comp){
        this.comp = comp
    }

    // 订单状态下拉框的内容数据
    getOrderStatusList = () => {
        const {props} = this.comp;
        const {main} = props;

        return [{
            key: '1',
            label: main.json['gx6008-000078'], // 待离职
        }, {
            key: '2',
            label: main.json['gx6008-000079'], // 已离职
        }, {
            key: '3',
            label: main.json['gx6008-000080'], // 离职交接中
        }];
    }
  

    changeOrg =(value)=>{
        const{props,action} = this.comp
        const{main,dispatch,button} = props
        if(typeof value == 'string'){
            console.log(value);
            dispatch({
                type: 'main/update',
                payload: {
                    orgvalue: {},
                    widget:true,
                    widgetValue:value
                }
            }) 
            this.pubSub.publish('getWidgetTableData', {
                 value: value,
            });
        }else{
            dispatch({
                type: 'main/update',
                payload: {
                    orgvalue: value,
                    widget:false
                }
            }) 
            if(value){
                button.setButtonVisible({
                    'query': true,
                    'confirm': true,
                    'print': true,
                    'printjjd': true,
                    'printzm': true
                })
            }
            if(value.refpk){
                this.pubSub.publish('queryTableData', {
                    pk_org: value.refpk
                });
            }  
        }
        
    }

    // 选择订单状态
    changeOrderStatus = (value) => {
        const{props} = this.comp
        const{dispatch,button} = props
        dispatch({
            type: 'main/update',
            payload: {
                orderStatus: value
            }
        });
        if(value === '2'){
            button.setButtonDisabled({
                confirm: true
            })
        }
        this.pubSub.publish('queryTableData', {
            billstate: value
        });
    }
    
    back =()=>{
        const {props} = this.comp
        const {dispatch,button} = props
        dispatch({
            type: 'main/update',
            payload: {
               showPage: 'list',
               showChangePage: false
            }
        })
        if(main.widget){
            this.pubSub.publish('getWidgetTableData');
            button.setButtonVisible({
                'query': false,
                'confirm': false,
                'print': false,
                'printjjd': false,
                'printzm': false
            })
        }else{
            this.pubSub.publish('queryTableData',{});
            button.setButtonVisible({
                'query': true,
                'confirm': true,
                'print': true,
                'printjjd': true,
                'printzm': true
            })
        }
    }

    handlePageInfoChange =(props, flag, status = 1, callback = () => {
    })=>{
        const {action} = this.comp
        const {main} = props
        if (flag) {
            props.cardPagination.getNextCardPaginationId({ id: flag, status: status });
            props.cardPagination.setCardPaginationId({ id: flag, status: status });
        }
        if (status == 3) {
            return false;
        }
        let _this = this
        //删除 会走向上一个或者下一个
        let orginPks = cacheTools.get('allpks')
        if (orginPks.length > 0) {
            orginPks.forEach((billid, index) => {
                if (flag &&  billid === flag) {
                    action.bodyAction.queryDataDetail({
                        billid: billid,
                        pk_org: main.orgvalue.refpk
                    })
                }
            })
        }else{
            this.back()
        }
    }
}